package com.huarui.payable.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.ewaf.framework.action.BaseAction;
import org.ewaf.framework.model.ListModel;

import com.huarui.initial.util.InitialUtil;
import com.huarui.payable.service.PayableService;
import com.huarui.user.model.SessionMessage;
import com.huarui.user.security.UserHolder;
import com.huarui.util.JsonUtil;
import com.opensymphony.xwork2.Action;

public class PayableAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Integer start;
	private Integer limit;
	private String sort;
	private String dir;
	
	private String searchConditions;
	private String idsnot;

	private PayableService payableService;
	@SuppressWarnings("unchecked")
	private ListModel listModel=new ListModel();
	private Integer customerId;
	private Integer status;
	private SessionMessage sm;
	private Map<String,Object> resultMap=new HashMap<String, Object>();
	
	@SuppressWarnings("unchecked")
	public String extList(){
		sm=UserHolder.getCurrentSessionMessage();
		Map map=new HashMap();
		if(dir!=null)listModel.setDesc(dir.equals("DESC")?true:false);
		listModel.setOrderBy(sort);
		listModel.setPage(start==null?0:start/limit+1);
		listModel.setPageSize(limit==null?10:limit);
		if(searchConditions!=null){
			List conditions = new ArrayList();
			InitialUtil.addToCollection(conditions, InitialUtil.split(searchConditions, " ,"));
			map.put("conditions",conditions);
		}
		if(idsnot!=null){
			Integer[] idsArray=JsonUtil.getIntegerArray4Json(idsnot);
			map.put("idsnot", idsArray);
		}
		if(customerId!=null){
			map.put("customerId", customerId);
		}
		if(status!=null){
			map.put("status", status);
		}
		map.put("companyId", sm.getCompanyId());
		List resultList=payableService.getPayableByConditions(listModel,map);
		resultMap.put("totalProperty", listModel.getTotal());
		resultMap.put("root", resultList);
		return Action.SUCCESS;
	}
	
	@SuppressWarnings("unchecked")
	public String getPayablesBycustomerId(){
		sm=UserHolder.getCurrentSessionMessage();
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("companyId", sm.getCompanyId());
		map.put("customerId", customerId);
		//map.put("unPaidNotZero", true);
		map.put("status", 0);
		List<Map> list=payableService.getPayableByConditions(map);
		resultMap.put("root", list);
		return Action.SUCCESS;
	}

	public Map<String, Object> getResultMap() {
		return resultMap;
	}

	public void setResultMap(Map<String, Object> resultMap) {
		this.resultMap = resultMap;
	}

	public void setStart(Integer start) {
		this.start = start;
	}

	public void setLimit(Integer limit) {
		this.limit = limit;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public void setDir(String dir) {
		this.dir = dir;
	}

	public void setSearchConditions(String searchConditions) {
		this.searchConditions = searchConditions;
	}

	public void setPayableService(PayableService payableService) {
		this.payableService = payableService;
	}

	@SuppressWarnings("unchecked")
	public void setListModel(ListModel listModel) {
		this.listModel = listModel;
	}


	public void setCustomerId(Integer customerId) {
		this.customerId = customerId;
	}

	public void setSm(SessionMessage sm) {
		this.sm = sm;
	}

	public void setIdsnot(String idsnot) {
		this.idsnot = idsnot;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}
	
	
	
}
